function details(id) {
	$('#yhxxDetails').window('open');
	$('#dgDetails').datagrid({
		height : backendCommon.getHeight(0.43),
		loadMsg : "数据装载中,请稍等....",
		url : mainDomain + '/yhxx/details.action?id='+id,
		nowrap : false,
		rownumbers : true,
		fitColumns : false,
		pagination : true,
		singleSelect : true,
		pageSize : 10,
		pageNumber : 1,
		pageList : [ 10, 15, 20 ],
		columns : [ [ {
			field : 'id',
			checkbox : true
		}, {
			field : 'yhxxVO.qyqc',
			title : '企业全称',
			width : $(this).width() * 0.08,
			align : 'center',
			formatter : function(value, rec, index) {
				return (!rec.yhxxVO.qyqc) ? "暂无" : rec.yhxxVO.qyqc;
			}
		}, {
			field : 'yhxxVO.qyjc',
			title : '企业简称',
			width : $(this).width() * 0.05,
			align : 'center',
			formatter : function(value, rec, index) {
				return (!rec.yhxxVO.qyjc) ? "暂无" : rec.yhxxVO.qyjc;
			}
		}, {
			field : 'qydm',
			title : '审核代码',
			width : $(this).width() * 0.05,
			align : 'center',
			formatter : function(value, rec, index) {
				return (!value) ? "暂无" : value;
			}
		}, {
			field : 'shcl',
			title : '审核材料',
			width : $(this).width() * 0.25,
			align : 'center',
			formatter : function(value, rec, index) {
				return (!value) ? "暂无" : "<a href=\""+value+"\" target=\"_blank\">" + value + "</a>";
			}
		}, {
			field : 'cllx',
			title : '材料类型',
			width : $(this).width() * 0.05,
			align : 'center',
			formatter : function(value, rec, index) {
				if (1 == value) {
					return "营业执照";
				}
				if (2 == value) {
					return "组织机构代码证";
				}
				if (3 == value) {
					return "税务登记证";
				}
				if (4 == value) {
					return "企业资质";
				}
				if (5 == value) {
					return "企业注册委托证明";
				}
				if (6 == value) {
					return "三证合一";
				}
				return "暂无";
			}
		} ] ]
	});
}


function doSearch(){
	$('#yhxxDatagrid').datagrid('load',{
		qyqc: $('#qyqc').val()/*,
		yhlx: $('#yhlx').val()*/
	});
}


function queryData(){
    $('#yhxxDg').datagrid('load',{
    	hydj: $('#hydj').combobox('getValue'),
    	yhlx: $('#yhlx').combobox('getValue'),
    	qyqc: $('#qyqc').val(),
    	lxrxm: $('#lxrxm').val()
    });
}


function qyqcFormatter(val, row) {
	if (!val) {
		return val;
	}
	return '<a href="javascript:void(0)" onclick="javascript:details(' + row.id
			+ ');">' + val + '</a>';
}

/*function qylxFormatter(val, row) {
	if (0 == val) {
		return "船贷";
	}
	if (1 == val) {
		return "货贷";
	}
	if (2 == val) {
		return "船公司";
	}
	if (3 == val) {
		return "船主";
	}
	if (4 == val) {
		return "货源企业";
	}
	if (5 == val) {
		return "集卡运输企业";
	}
	if (6 == val) {
		return "仓库";
	}
	if (7 == val) {
		return "港口";
	}
	if (8 == val) {
		return "个人";
	}
}*/

function jydjFormatter(val, row) {
	if (1 == val) {
		return "一星";
	}
	if (2 == val) {
		return "二星";
	}
	if (3 == val) {
		return "三星";
	}
	if (4 == val) {
		return "四星";
	}
	if (5 == val) {
		return "五星";
	}
}

function qcFormatter(val, row) {
	return (!row.yhxxVO) ? "暂无" : row.yhxxVO.qyqc;
}

function jcFormatter(val, row) {
	return (!row.yhxxVO) ? "暂无" : row.yhxxVO.qyjc;
}

function cllx(val, row) {
	if (1 == val) {
		return "营业执照";
	}
	if (2 == val) {
		return "组织机构代码证";
	}
	if (3 == val) {
		return "税务登记证";
	}
	if (4 == val) {
		return "企业资质";
	}
	if (5 == val) {
		return "企业注册委托证明";
	}
	if (6 == val) {
		return "三证合一";
	}
	return "未知";
}

function optFormatter(val, row) {
	if(1 == val){
		return "审核通过";
	 }
	 if(2 == val){
		return "审核未通过";
	 }
	var oprate = '<div><a class="btn_blue06"  id="editbtn" onclick="javascript:pass('
			+ row.id + ')" href="javascript:void(0)">通过</a></div>';
	oprate += '<div><a class="btn_blue06"  id="editbtn" onclick="javascript:reject('
			+ row.id + ')" href="javascript:void(0)">拒绝</a></div>';
	oprate += '<div><a class="btn_blue06"  id="editbtn" onclick="javascript:del('
			+ row.id + ')" href="javascript:void(0)">删除</a></div>';
	return oprate;
}

/**
 * 删除
 * 
 * @param id
 */
function del(id) {
	$.messager.confirm('确认', '确认删除？', function(confirm) {
		if (confirm) {
			$.ajax({
				type : "POST",
				url : mainDomain + '/yhxx/delete/' + id + '.action',
				dataType : "JSON",
				success : function(result) {
					if (result.success) {
						$('#dgDetails').datagrid('reload');
					} else {
						$.messager.alert('提示', result.message, 'info');
					}
				}
			});
		}
	});
}

/**
 * 通过
 * 
 * @param id
 */
function pass(id) {
	$.messager.confirm('确认', '确认审核通过？', function(confirm) {
		if (confirm) {
			$.ajax({
				type : "POST",
				url : mainDomain + '/yhxx/audit.action',
				data : {
					yhzt : 1,
					id : id,
					jjyy : '审核通过'
				},
				dataType : "JSON",
				success : function(result) {
					if (result.success) {
						$('#yhxxDatagrid').datagrid('reload');
					} else {
						$.messager.alert('提示', result.message, 'info');
					}
				}
			});
		}
	});
}

/**
 * 拒绝
 * 
 * @param id
 */
function reject(id) {
	$.messager.prompt('审核拒绝', '请输入审核拒绝原因', function(data) {
		if (!data) {
			$.messager.alert('提示', "必须输入拒绝原因!", 'info');
			return;
		}
		$.ajax({
			type : "POST",
			url : mainDomain + '/yhxx/audit.action',
			data : {
				yhzt : 2,
				id : id,
				jjyy : data
			},
			dataType : "JSON",
			success : function(result) {
				if (result.success) {
					$.messager.alert('提示', result.message, 'info');
					$('#yhxxDatagrid').datagrid('reload');
				} else {
					$.messager.alert('提示', result.message, 'info');
				}
			}
		});
	});
}


function pwdDlg() {
    var row = $('#yhxxDg').datagrid('getSelected');
    if(!row){
        $.messager.alert('提示', "请选择一条数据!", 'info');
        return;
    }
    $('#pwdfm').form('load', {
        id: row.dlxxVO.id,
        mm:'',
        confirm:''
    });
    $('#pwdDlg').dialog('open').dialog('center');
}



function pwdSave() {
	$('#pwdfm').form('submit', {
		onSubmit : function() {
			return $(this).form('validate');
		},
		success : function(result) {
			var result = eval('(' + result + ')');
			if (result.success) {
				$.messager.alert('提示', '修改成功', 'info');
				$('#pwdDlg').dialog('close');
			} else {
				$.messager.alert('提示', result.message, 'info');
			}
		}
	});
}


$.extend($.fn.validatebox.defaults.rules, {
    notEquals: {
		validator: function(value, param){
			return value == $(param[0]).val();
		},
		message: "{1}"
    }
});



$.extend($.fn.datagrid.methods, {
    editCell: function(jq, param){
        return jq.each(function(){
            var opts = $(this).datagrid('options');
            var fields = $(this).datagrid('getColumnFields',true).concat($(this).datagrid('getColumnFields'));
            for(var i=0; i<fields.length; i++){
                var col = $(this).datagrid('getColumnOption', fields[i]);
                col.editor1 = col.editor;
                if (fields[i] != param.field){
                    col.editor = null;
                }
            }
            $(this).datagrid('beginEdit', param.index);
            for(var i=0; i<fields.length; i++){
                var col = $(this).datagrid('getColumnOption', fields[i]);
                col.editor = col.editor1;
            }
        });
    }
});


var editIndex = undefined;
function endEditing(){
    if (editIndex == undefined){
        return true
    }
    if ($('#yhxxDg').datagrid('validateRow', editIndex)){
        var ed = $('#yhxxDg').datagrid('getEditor', {index:editIndex, field:'hydj'});
        if(!ed){
            editIndex = undefined;
            return;
        }
        var row = $('#yhxxDg').datagrid('getRows');
        var hydj = $(ed.target).combobox('getValue');
        $('#yhxxDg').datagrid('endEdit', editIndex);
        $.ajax({
            type : "POST",
            url : mainDomain + '/yhxx/dj.action',
            data : {
                id : row[editIndex]['id'],
                hydj : hydj
            },
            dataType : "JSON",
            success : function(result) {
                if (result.success) {
                    $('#yhxxDg').datagrid('reload');
                    editIndex = undefined;
                } else {
                    $.messager.alert('提示', result.message, 'info');
                }
            }
        });
        return true;
    } else {
        editIndex = undefined;
        return false;
    }
}
function onClickCell(index, field){
    if (endEditing()){
        $('#yhxxDg').datagrid('selectRow', index)
                .datagrid('editCell', {index:index, field:field});
        editIndex = index;
    }
}

function settjDlg() {
    var row = $('#yhxxDg').datagrid('getSelected');
    if(!row){
        $.messager.alert('提示', "请选择一条数据!", 'info');
        return;
    }
    $('#ff').form('load', {
        id: row.id,
        qydt:row.qydt,
        ylzd2:row.ylzd2
    });
    $('#settjDlg').dialog('open').dialog('center');
}

function tjSave() {
	$('#ff').form('submit', {
		onSubmit : function() {
			return $(this).form('validate');
		},
		success : function(result) {
			var result = eval('(' + result + ')');
			if (result.success) {
				$('#settjDlg').dialog('close');
				$('#yhxxDg').datagrid('reload');
			} else {
				$.messager.alert('提示', result.message, 'info');
			}
		}
	});
}

function istjFormatter(val, row){
	if (0 == val) {
		return "否";
	}
	if (1 == val) {
		return "是";
	}
}

function isdjFormatter(val, row){
	if (0 == row.dlxxVO.sfdj) {
		return "否";
	}
	if (1 == row.dlxxVO.sfdj) {
		return "是";
	}
}

function rqFormatter(val, row) {
	return (!val) ? "暂无" : backendCommon.dateTimeToLocalStringWithSeconds(val);
}

function setdjDlg() {
    var row = $('#yhxxDg').datagrid('getSelected');
    if(!row){
        $.messager.alert('提示', "请选择一条数据!", 'info');
        return;
    }
    $('#djform').form('load', {
        id: row.dlxxVO.id,
        sfdj:row.dlxxVO.sfdj,
        djlx:row.dlxxVO.djlx
    });
    $('#setdjDlg').dialog('open').dialog('center');
}

function djSave() {
	$('#djform').form('submit', {
		onSubmit : function() {
			return $(this).form('validate');
		},
		success : function(result) {
			var result = eval('(' + result + ')');
			if (result.success) {
				$.messager.alert('提示', '冻结设置成功', 'info');
				$('#setdjDlg').dialog('close');
				$('#yhxxDg').datagrid('reload');
			} else {
				$.messager.alert('提示', result.message, 'info');
			}
		}
	});
}